<?php
session_start();
include_once("config/config.inc.php");
include_once("dailyreport.function.php");
$act = $_POST["act"];
$user_id = $_SESSION["hotel"]["userid"];
$amount = $_POST["new_tendered1"];

$datetime = date("Y-m-d H:i:s");
$shift = "end";
$amount = $_POST["new_tendered1"];
$deno_1 = $_POST["txt1"];
$deno_5 = $_POST["txt5"];
$deno_10 = $_POST["txt10"];
$deno_20 = $_POST["txt20"];
$deno_50 = $_POST["txt50"];
$deno_100 = $_POST["txt100"];
$deno_500 = $_POST["txt500"];
$deno_1000 = $_POST["txt1000"];
$oic_user_id = "";
$to_user_id = "";


function getLatestShifts($shiftid)
{
	$sql = "SELECT `shift-transaction_id`,datetime,user_id  FROM `shift-transactions` where shift = 'start' order by datetime desc ";
	$res = mysql_query($sql);
	$ret = "<select name='rblshifts' id='rblshifts' onchange='myform.submit();'>";
	$ret .= "<option value=''>&nbsp;</option>";
	while(list($shift_transaction_id,$datetime,$userid)=mysql_fetch_row($res))
	{
		if($shiftid == $shift_transaction_id)
		{
			$select = "selected";
		}else
		{
			$select = " ";
		}
		$_sql = "select fullname from users where user_id = '$userid'";
		$_res = mysql_query($_sql);
		list($username)=mysql_fetch_row($_res);
		$ret .= "<option value='$shift_transaction_id' $select>$datetime - $username - ".getshift($datetime)."</option>";
	}
	$ret .= "</select>";

	return $ret;
}

$shiftid = $_POST["rblshifts"];
$sql = "select datetime,user_id from `shift-transactions` where `shift-transaction_id` = '$shiftid'";
$res = mysql_query($sql);
list($sdatetime,$suser_id)=mysql_fetch_row($res);
$startshift = $sdatetime;


$sql = "select datetime,user_id from `shift-transactions` where datetime  > '$startshift' order by datetime asc limit 0,1";
$res = mysql_query($sql);
list($edatetime,$euser_id)=mysql_fetch_row($res);
$end = $edatetime;

if(!$end)
{
	$end = date("Y-m-d H:i:s");
}


function getshift($date) {
	if(!$date)$date=date("Y-m-d H:i:s");
	list($d, $t) = explode(" ", $date);
	list($h, $m, $s) = explode(":", $t);
	$sql = "select shift_id from shifts where $h between shift_start and shift_end";
	$res = mysql_query($sql) or die(mysql_error() .$sql);
	list($shift)=mysql_fetch_row($res);
	
	if($h==16||$h==15)
	{
		return $shift = "3rd";
	}
	elseif($h==8||$h==7)
	{
		return $shift = "2nd";
	}
	return  "1st";
}


?>

<form name=myform method=post>
<div>
<? echo getLatestShifts($shiftid); ?>
</div>
<br>
<a href="#">Print Report</a>
<br>
<br>
<div class='printable'>
<? echo getSalesTransaction(0,$startshift,$end) ?>
</div><br />
<a href="#">Print Report</a>
</form>